from typing import List


class Solution:
    def minSubArrayLen(self, target: int, nums: List[int]) -> int:
        a, b = 0, 0

        ans = float("inf")
        now = 0
        while a < len(nums):
            while now < target and b < len(nums):
                now += nums[b]
                b += 1

            if now >= target:
                ans = min(ans, b - a)
            else:
                break

            now -= nums[a]
            a += 1

        return ans if ans != float("inf") else 0


if __name__ == "__main__":
    print(Solution().minSubArrayLen(target=7, nums=[2, 3, 1, 2, 4, 3]))  # 2
    print(Solution().minSubArrayLen(target=4, nums=[1, 4, 4]))  # 1
    print(Solution().minSubArrayLen(target=11, nums=[1, 1, 1, 1, 1, 1, 1, 1]))  # 0
